var app = new Vue({
    el: ".box",
    data: {
        form: {
            emails: '',
            titles: '',
            conts: '',
        },
        loading:false
    },
    methods: {
        onSubmit() {
            var d = this.form;
            if (!d.emails) {
                this.$message({
                    message: '请输入收件人邮箱',
                    type: 'warning'
                });
                return false;
            };
            if (!d.titles) {
                this.$message({
                    message: '请输入邮件标题',
                    type: 'warning'
                });
                return false;
            };
            if (!d.conts) {
                this.$message({
                    message: '请输入邮件内容',
                    type: 'warning'
                });
                return false;
            };
            var datas_email = {
                token: (sessionStorage.getItem('token')),
                head: 20000,
                emails: app.form.emails,
                titles: app.form.titles,
                conts: app.form.conts
            }
            var loading = app.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            axios({
                method: "POST",
                baseURL: "../../api/sendmail.php",
                headers: { "Content-type": "application/json; charset=utf-8" },
                data: JSON.stringify(datas_email)
            }).then(function (res) {
                loading.close();
                if (res.status === 200) {
                    app.$message({
                        message: '操作成功~',
                        type: 'success'
                    });
                };
                console.log(res.data);
            }).catch(function (res) {
                console.log(res);
            });

        },
        get_email() {
            this.loading = !this.loading;
            // var loading = app.$loading({
            //     lock: true,
            //     text: 'Loading',
            //     spinner: 'el-icon-loading',
            //     background: 'rgba(0, 0, 0, 0.7)'
            // });
            axios({
                method: "POST",
                baseURL: "../../api/subscribe.php",
                headers: { "Content-type": "application/json; charset=utf-8" },
                data: JSON.stringify({head:20001,token: (sessionStorage.getItem('token'))})
            }).then(function (res) {
                // loading.close();
                if (res.status === 200) {
                  app.form.emails = res.data.data;
                  app.loading = false;
                };
            }).catch(function (res) {
                console.log(res);
            });
        }
    },
    mounted(){
        var email = window.location.href.includes('?email=') ? window.location.href.split('?email=')[1] : '';
        this.form.emails = email;
    }
});